package com.springboot.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.mapper.UserMapper;
import com.springboot.model.User;
import com.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Author: TongRui乀
 * @Date: 2019-12-03 18:07
 * @description：
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public void insert(User user) {
        this.userMapper.insert(user);
    }

    @Cacheable(value = "userInfoCache", key = "#id", condition = "#id % 2 == 0")
    @Override
    public User getByUserId(int id) {
        return this.userMapper.selectById(id);
    }

    @CacheEvict(value = "userInfoCache", key = "#user.id", condition = "#id % 2 == 0")
    @Override
    public void updateByUserId(User user) {
        this.userMapper.updateById(user);
    }
}
